/**
* Created by ren on 2017/1/6.
*/
<template>
  <div class='myGold'>
    <template v-if="_parentThis.goldChild==='parent'">
      <ul class="head">
        <li>类型</li>
        <li>金蛋</li>
        <li>日期</li>
      </ul>
      <ul class="body">
        <li v-for="(item,index) in goldData">
          <div>{{item.sourceName}}</div>
          <div :class="{number:true,plus:item.type==='+'}">{{item.type+item.number}}</div>
          <div>{{item.createTime}}</div>
        </li>
      </ul>
    </template>
    <template v-if="_parentThis.goldChild==='aboutMyGold'">
      <AboutMyGold></AboutMyGold>
    </template>
    <div style="margin-top: 10px;position: absolute;top: 36px;right: 15px;font-size: 18px"  v-if="_parentThis.goldChild==='parent'">
      <span style="float:right;color:#e6760a;cursor: pointer" @click="cut('aboutMyGold')">如何获得金蛋？</span>
    </div>
    <Notify :parentThis='this'></Notify>
  </div>
</template>

<script>
  import API from '../../api'
  import Notify from '../Notify'
  import AboutMyGold from './AboutMyGold'
  export default {
    name: 'myGold',
    components: {
      Notify,
      AboutMyGold
    },
    data: function () {
      return {
        notifyStatus: 2,
        goldData: []
      }
    },
    props: ['_parentThis'],
    methods: {
      cut: function (name) {
        this._parentThis.goldChild = name
        switch (name) {
          case 'parent':
            this._parentThis.titHtml = '<span>我的金蛋</span>'
            break
          case 'aboutMyGold':
            this._parentThis.titHtml = '<span>我的金蛋 > <span style="color: #f48315;">关于金蛋</span></span>'
            break
        }
      },
      findGoldBeanDetailList: function () {
        this.$http.post(API.findGoldBeanDetailList, {
          userId: this.$cookie.get('id'),
          nextPage: 0,
          pageSize: 10000
        }).then((ret) => {
          const result = ret.body
          if (result.code === 1) {
            this.goldData = result.object.content
          } else {
            this.notifyStatus = '0|' + result.message
          }
        }, (err) => {
          console.log(err)
        })
      },
      findMyAssets: function () {
        this.$http.post(API.findMyAssets, {
          id: this.$cookie.get('id')
        }).then((ret) => {
          const result = ret.body
          if (result.code === 1) {
            this.cash = (result.object.cash / 100).toFixed(2)
            this._parentThis.titHtml = '<span>我的金蛋<span style="margin-left: 10px">(<span style="color:#e6760a;">' + result.object.glodBean + '个</span>)</span></span>'
          } else {
            this.notifyStatus = '0|' + result.message
          }
        }, (err) => {
          console.log(err)
        })
      }
    },
    mounted: function () {
      this.findGoldBeanDetailList()
      this.findMyAssets()
      this._parentThis.cutName = 'myGold'
    }
  }
</script>

<style>
  .myGold {
  }
</style>